package com.sample.command
{
	import com.sample.Constants;
	import com.sample.model.ModelLocator;
	import com.sample.remote.MainConnectionManager;
	import com.sample.view.LoginView;
	import com.trg.flex.remote.RemoteCallManager;
	
	import mx.binding.utils.ChangeWatcher;
	import mx.events.PropertyChangeEvent;
	
	public class InitializationCommand
	{
		public static function get i():InitializationCommand {
			return new InitializationCommand();
		}
		
		public function execute():void {
			RemoteCallManager.instance().registerConnection(MainConnectionManager.instance(), true);
			
			//LoginView
			LoginView.instance().show();
			ChangeWatcher.watch(ModelLocator.getInstance(), "sessionState", function(event:PropertyChangeEvent):void {
				if (event.newValue == Constants.SESSION_STATE_LOGGED_IN) {
					LoginView.instance().hide();
				} else {
					LoginView.instance().show();
				}
			});
			
			SessionCommands.i.refreshState();
		}

	}
}